package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.generator.entity.DeviceSiteEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.renren.modules.generator.entity.CodeDicEntity;
import io.renren.modules.generator.service.CodeDicService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 代码字典
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-20 15:18:43
 */
@RestController
@RequestMapping("generator/codedic")
@Api("代码字典接口")
public class CodeDicController {
    @Autowired
    private CodeDicService codeDicService;

    /**
     * 列表
     */
    @RequestMapping("/all/list")
    @ApiOperation("获取所有")
    public R alllist(@RequestBody(required = true) CodeDicEntity codeDicEntity){
        List<CodeDicEntity> codeDicEntityList = codeDicService.selectAll(codeDicEntity);

        return R.ok().put("data", codeDicEntityList);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params,@RequestBody(required = false) CodeDicEntity codeDicEntity){
        PageUtils page = codeDicService.queryPage(params,codeDicEntity);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("id") Integer id){
		CodeDicEntity codeDic = codeDicService.getById(id);

        return R.ok().put("codeDic", codeDic);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody CodeDicEntity codeDic){
		codeDicService.save(codeDic);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody CodeDicEntity codeDic){
		codeDicService.updateById(codeDic);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids){
		codeDicService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
